# Python中的内置容器
# 字典 dict
# dict1 = {'name': '张三', 'age': 18}
# # 通过 dict 函数 将列表转化为字典
# list1 = [('name', '张三'), ('age', 18)]
# dict2 = dict(list1)
# print(dict2)
# # 通过dict函数创建字典
# dict3 = dict(name='李四', age=28)
# print(dict3)

# dict1 = {'name': '张三', 'age': 18}
# # 字典修改操作
# dict1['age'] = '刚满18'
# print(dict1)
# # 字典新增操作
# dict1['address'] = '北京'
# print(dict1)
#
# # 字典删除操作
# dict1.pop('name')  # 删除字典指定元素
# print(dict1)
# del dict1['age']  # del传入key删除指定键值对
# print(dict1)
# dict1.clear()  # 清空字典全部元素
# print(dict1)

# 字典查找操作
# dict1 = {'name': '张三', 'age': 18, 'address': '北京'}
# if 'address' in dict1:
#     print(dict1['address'])

# 字典中的函数

# fromkeys
# new_dict = dict.fromkeys(['name', 'age'])
# print(f'函数fromkeys: {new_dict}')
# new_dict['name'] = '李四'
# new_dict['age'] = '刚满18'
# print(new_dict)

# new_dict = {'name': '张三', 'age': 18, 'address': '北京'}
# # items
# items = new_dict.items()
# print(f'函数items: {items}')
# # get
# age = new_dict.get('age')
# print(f'函数get: {age}')
# # keys
# keys = new_dict.keys()
# print(f'函数key: {keys}')
# # values
# values = new_dict.values()
# print(f'函数values: {values}')

# 字典的遍历
# new_dict = {'name': '张三', 'age': 18, 'address': '北京'}
# for k,v in new_dict.items():
#     print(f'key={k}, value={v}')
#
# for k in new_dict.keys():
#     print(f'{k} ', end='')    # 遍历打印所有的键
# print()
# for v in new_dict.values():
#     print(f'{v} ', end='')    # 遍历打印所有的值


# 集合 Set
# set1 = set()  # 空集合
# set2 = {'abcd', 100, 78, 3.14}
# print(len(set2))
#
# # 添加
# set2.add(99)
# set2.add('hello')
# print(set2)
#
# # 删除
# set2.remove(100)
# print(set2)
#
# # for 遍历
# for i in set2:
#     print(f'{i} ', end='')

# 集合set中任意元素时不能为列表的
# set3 = {'hello', (100, 200), [300, 400]}
# print(set3)

# 可变与不可变
# str1 = 'helloword'
# print(id(str1))
#
# str1 = 'abcdefg'  # 修改后的字符串，内存地址也修改
# print(id(str1))


list1 = [100, 200, 300]
print(id(list1))
list1.append(500)
list1.pop(1)
print(id(list1))
